from django.core.management.base import BaseCommand
from navigation.models import Category, Link, Tag
from django.utils import timezone
import random

class Command(BaseCommand):
    help = 'Generate sample navigation data'

    def handle(self, *args, **options):
        # Sample categories
        categories = [
            "开发工具", "编程语言", "框架", "数据库", "云服务",
            "运维工具", "测试工具", "版本控制", "IDE", "API工具",
            "前端框架", "后端框架", "移动开发", "人工智能", "大数据",
            "区块链", "安全工具", "容器技术", "监控工具", "文档工具"
        ]
        
        # Sample links for each category
        links_data = {
            "开发工具": [
                ("Visual Studio Code", "https://code.visualstudio.com/"),
                ("PyCharm", "https://www.jetbrains.com/pycharm/"),
                ("Sublime Text", "https://www.sublimetext.com/"),
                ("WebStorm", "https://www.jetbrains.com/webstorm/"),
                ("Atom", "https://atom.io/"),
                ("Vim", "https://www.vim.org/"),
            ],
            "编程语言": [
                ("Python", "https://www.python.org/"),
                ("JavaScript", "https://developer.mozilla.org/en-US/docs/Web/JavaScript"),
                ("Java", "https://www.java.com/"),
                ("Go", "https://golang.org/"),
                ("Rust", "https://www.rust-lang.org/"),
                ("TypeScript", "https://www.typescriptlang.org/"),
            ],
            "框架": [
                ("React", "https://reactjs.org/"),
                ("Vue.js", "https://vuejs.org/"),
                ("Angular", "https://angular.io/"),
                ("Django", "https://www.djangoproject.com/"),
                ("Flask", "https://flask.palletsprojects.com/"),
                ("Spring Boot", "https://spring.io/projects/spring-boot"),
            ],
            "数据库": [
                ("MySQL", "https://www.mysql.com/"),
                ("PostgreSQL", "https://www.postgresql.org/"),
                ("MongoDB", "https://www.mongodb.com/"),
                ("Redis", "https://redis.io/"),
                ("SQLite", "https://www.sqlite.org/"),
                ("Elasticsearch", "https://www.elastic.co/"),
            ],
            "云服务": [
                ("AWS", "https://aws.amazon.com/"),
                ("Google Cloud", "https://cloud.google.com/"),
                ("Azure", "https://azure.microsoft.com/"),
                ("阿里云", "https://www.aliyun.com/"),
                ("腾讯云", "https://cloud.tencent.com/"),
                ("华为云", "https://www.huaweicloud.com/"),
            ],
            "运维工具": [
                ("Docker", "https://www.docker.com/"),
                ("Kubernetes", "https://kubernetes.io/"),
                ("Jenkins", "https://www.jenkins.io/"),
                ("Ansible", "https://www.ansible.com/"),
                ("Terraform", "https://www.terraform.io/"),
                ("Prometheus", "https://prometheus.io/"),
            ],
            "测试工具": [
                ("Jest", "https://jestjs.io/"),
                ("Pytest", "https://pytest.org/"),
                ("Selenium", "https://www.selenium.dev/"),
                ("JUnit", "https://junit.org/"),
                ("Postman", "https://www.postman.com/"),
                ("Cypress", "https://www.cypress.io/"),
            ],
            "版本控制": [
                ("GitHub", "https://github.com/"),
                ("GitLab", "https://gitlab.com/"),
                ("Bitbucket", "https://bitbucket.org/"),
                ("Gitee", "https://gitee.com/"),
                ("SVN", "https://subversion.apache.org/"),
                ("Mercurial", "https://www.mercurial-scm.org/"),
            ],
            "IDE": [
                ("IntelliJ IDEA", "https://www.jetbrains.com/idea/"),
                ("Eclipse", "https://www.eclipse.org/"),
                ("Android Studio", "https://developer.android.com/studio"),
                ("Xcode", "https://developer.apple.com/xcode/"),
                ("NetBeans", "https://netbeans.apache.org/"),
                ("CLion", "https://www.jetbrains.com/clion/"),
            ],
            "API工具": [
                ("Swagger", "https://swagger.io/"),
                ("Postman", "https://www.postman.com/"),
                ("Insomnia", "https://insomnia.rest/"),
                ("cURL", "https://curl.se/"),
                ("GraphQL", "https://graphql.org/"),
                ("FastAPI", "https://fastapi.tiangolo.com/"),
            ],
            "前端框架": [
                ("React", "https://reactjs.org/"),
                ("Vue.js", "https://vuejs.org/"),
                ("Angular", "https://angular.io/"),
                ("Svelte", "https://svelte.dev/"),
                ("Next.js", "https://nextjs.org/"),
                ("Nuxt.js", "https://nuxtjs.org/"),
            ],
            "后端框架": [
                ("Django", "https://www.djangoproject.com/"),
                ("Spring Boot", "https://spring.io/projects/spring-boot"),
                ("Express", "https://expressjs.com/"),
                ("Laravel", "https://laravel.com/"),
                ("Ruby on Rails", "https://rubyonrails.org/"),
                ("ASP.NET Core", "https://dotnet.microsoft.com/apps/aspnet"),
            ],
            "移动开发": [
                ("React Native", "https://reactnative.dev/"),
                ("Flutter", "https://flutter.dev/"),
                ("Ionic", "https://ionicframework.com/"),
                ("Swift", "https://developer.apple.com/swift/"),
                ("Kotlin", "https://kotlinlang.org/"),
                ("Xamarin", "https://dotnet.microsoft.com/apps/xamarin"),
            ],
            "人工智能": [
                ("TensorFlow", "https://www.tensorflow.org/"),
                ("PyTorch", "https://pytorch.org/"),
                ("scikit-learn", "https://scikit-learn.org/"),
                ("OpenAI", "https://openai.com/"),
                ("Keras", "https://keras.io/"),
                ("Hugging Face", "https://huggingface.co/"),
            ],
            "大数据": [
                ("Hadoop", "https://hadoop.apache.org/"),
                ("Spark", "https://spark.apache.org/"),
                ("Flink", "https://flink.apache.org/"),
                ("Kafka", "https://kafka.apache.org/"),
                ("Hive", "https://hive.apache.org/"),
                ("Tableau", "https://www.tableau.com/"),
            ],
            "区块链": [
                ("Ethereum", "https://ethereum.org/"),
                ("Solidity", "https://soliditylang.org/"),
                ("Web3.js", "https://web3js.readthedocs.io/"),
                ("Truffle", "https://www.trufflesuite.com/"),
                ("MetaMask", "https://metamask.io/"),
                ("Hyperledger", "https://www.hyperledger.org/"),
            ],
            "安全工具": [
                ("Wireshark", "https://www.wireshark.org/"),
                ("Nmap", "https://nmap.org/"),
                ("Metasploit", "https://www.metasploit.com/"),
                ("Burp Suite", "https://portswigger.net/burp"),
                ("OWASP ZAP", "https://www.zaproxy.org/"),
                ("Kali Linux", "https://www.kali.org/"),
            ],
            "容器技术": [
                ("Docker", "https://www.docker.com/"),
                ("Kubernetes", "https://kubernetes.io/"),
                ("Podman", "https://podman.io/"),
                ("containerd", "https://containerd.io/"),
                ("OpenShift", "https://www.openshift.com/"),
                ("Rancher", "https://rancher.com/"),
            ],
            "监控工具": [
                ("Prometheus", "https://prometheus.io/"),
                ("Grafana", "https://grafana.com/"),
                ("Nagios", "https://www.nagios.org/"),
                ("Zabbix", "https://www.zabbix.com/"),
                ("New Relic", "https://newrelic.com/"),
                ("Datadog", "https://www.datadoghq.com/"),
            ],
            "文档工具": [
                ("Confluence", "https://www.atlassian.com/software/confluence"),
                ("GitBook", "https://www.gitbook.com/"),
                ("Notion", "https://www.notion.so/"),
                ("ReadTheDocs", "https://readthedocs.org/"),
                ("Docusaurus", "https://docusaurus.io/"),
                ("VuePress", "https://vuepress.vuejs.org/"),
            ],
        }

        # Create categories
        for cat_name in categories:
            category, created = Category.objects.get_or_create(
                name=cat_name,
                defaults={
                    'description': f'{cat_name}相关资源和工具',
                    'order': random.randint(1, 100)
                }
            )
            
            # Create links for this category
            if cat_name in links_data:
                for link_title, url in links_data[cat_name]:
                    Link.objects.get_or_create(
                        url=url,
                        defaults={
                            'title': link_title,
                            'description': f'{link_title}官方网站',
                            'category': category,
                            'visit_count': random.randint(0, 1000),
                            'is_active': True
                        }
                    )

        self.stdout.write(self.style.SUCCESS('Successfully generated navigation data'))
